//********************************************************************************************************************//
//ORGANIZATION:
//AUTHOR: bpeng(bogers.peng@gmail.com)
//SUMMARY:
//********************************************************************************************************************//
#include "../Exception.h"

using namespace Native::System;

//********************************************************************************************************************//
//CException
//********************************************************************************************************************//
CException::CException()
{
}

CException::CException(C_EXCEPTION& that) :
    CObject(that),
    _issues(that._issues)
{
}

CException::CException(C_EXCEPTION&& that) :
    CObject(that),
    _issues(that._issues)
{
}

CException::CException(C_SCENE& scene, WSTRING& detail)
{
    _issues.push_back(CCase(scene, L"Produce an exception", detail));
}

CException::CException(C_CASE& record)
{
    _issues.push_back(record);
}

bool CException::operator==(C_EXCEPTION& rvalue) const
{
    if (_issues.size() == rvalue._issues.size()) {
        for (int i = 0; i < _issues.size(); i++) {
            if (_issues[i] != rvalue._issues[i]) {
                return false;
            }
        }
    } else {
        return false;
    }

    return true;
}

bool CException::operator!=(C_EXCEPTION& rvalue) const
{
    return !operator==(rvalue);
}

wstring CException::Report() const
{
    wstring report(EMPTY_STRING);

    for (int i = 0; i < _issues.size(); i++)
    {
        report += _issues[i].ToString();
        report += L"\n";
    }

    return move(report);
}

void CException::Append(C_CASE& record)
{
    _issues.push_back(record);
}

CCase CException::LatestRecord() const
{
    return _issues[_issues.size()-1];
}

size_t CException::Count() const
{
    return _issues.size();
}

C_EXCEPTION& CException::operator=(C_EXCEPTION& rvalue)
{
    _issues = rvalue._issues;

    return *this;
}
